package com.sci.controller;

import com.sci.entity.User;
import com.sci.mapper.UserMapper;
import com.sci.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @Resource
    private UserMapper userMapper;

    @GetMapping("/by-wechat/{wechatId}")
    public User getByWechatId(@PathVariable(value = "wechatId") String wechatId) {
        return userMapper.selectByWechatId(wechatId);
    }
    @PutMapping("/username")
    public Boolean updateUsername(@RequestParam String wechatId,
                                  @RequestParam String newUsername) {
        return userService.updateUsername(wechatId, newUsername);
    }

    @PostMapping("/balance/deduct")
    public Boolean deductBalance(@RequestParam String wechatId,
                                 @RequestParam Double amount) {
        return userService.deductBalance(wechatId, amount);
    }
    @PostMapping("/register")
    public Boolean register(@RequestBody User user) {
        return userService.register(user);
    }
}
